package org.jks.util;

import java.io.BufferedReader;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class JsonUtil {

	public static String Object2Json(Object obj) {
		GsonBuilder b = new GsonBuilder();
		b.excludeFieldsWithoutExposeAnnotation();
		b.registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY);
		b.setDateFormat("yyyy-MM-dd HH:mm:ss");
		Gson gson = b.create();
		return gson.toJson(obj);
	}

	public static Object Json2Object(String json, Class<?> model) {
		Gson gson = new Gson();
		return gson.fromJson(json, model);
	}
	
	public static String getJson(BufferedReader reader){
		StringBuffer json = new StringBuffer();
		String line = null;
		try {
			while ((line = reader.readLine()) != null) {
				json.append(line);
			}
		} catch (Exception e) {
		}
		return json.toString();
	}

}
